home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group98c.txt
/
000139_icon-group-sender _Thu Dec 17 12:32:43 1998.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
1KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id MAA17561
for icon-group-addresses; Thu, 17 Dec 1998 12:32:26 -0700 (MST)
Message-Id: <199812171932.MAA17561@baskerville.CS.Arizona.EDU>
Date: Thu, 17 Dec 1998 11:07:13 -0800
From: kwalker@sfo.harbinger.com (Ken Walker)
To: icon-group@optima.CS.Arizona.EDU
Subject: Re: Small Icon programming problem
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
Here is a rather straightforward solution to the problem of
sorting digits while preserving the sign of an integer.
There should be a solution that is shorter and more obscure; I
thought of trying csets, but they discard duplicate digits...
Ken Walker, kenneth.walker@sfo.harbinger.com
Harbinger Coporation, Concord, Ca. 94520
procedure disort(i)
local digitLst, sortedInt;
#
# Separate the integer into a sign and a list of digits.
#
digitLst := [];
i ? {
sortedInt := tab(any('-+')) | ""
while put(digitLst, move(1));
}
#
# Sort the digits and append them to the output.
#
digitLst := sort(digitLst);
while sortedInt ||:= get(digitLst);
return integer(sortedInt);
end
(You can tell I've been programming too much in C by all the
semicolons at the end of lines; it also took me a few tries
to get all the colons before the equals. :-)